cmake_minimum_required(VERSION 3.16)

set(CMAKE_CXX_STANDARD 17)

# set(CMAKE_SYSTEM_NAME Linux)  # 设置目标系统名字
# set(CMAKE_SYSTEM_PROCESSOR arm)  # 设置目标处理器架构
# set(CROSSCOMPILER_PATH "/usr/local/bin/arm-none-linux-gnueabihf")  # 交叉编译器路径
# set(CMAKE_C_COMPILER "${CROSSCOMPILER_PATH}/bin/arm-none-linux-gnueabihf-gcc")
# set(CMAKE_CXX_COMPILER "${CROSSCOMPILER_PATH}/bin/arm-none-linux-gnueabihf-g++")

set (CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../buildroot/output/host/share/buildroot/toolchainfile.cmake")

project (UAV_Ctrl)
include_directories(${PROJECT_SOURCE_DIR}/plog/include ${PROJECT_SOURCE_DIR}/rapidjson/include)
# find_package(RapidJSON)
add_subdirectory(plog)
add_subdirectory(rapidjson)
add_subdirectory(src)

# 检查是否交叉编译
if(CMAKE_CROSSCOMPILING)
    message(STATUS "Cross-compiling detected...")
    # 交叉编译时链接的库
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_subdirectory(sensing_board_Linux_drivers)
        target_link_libraries(uav_test devices)
        target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/sensing_board_Linux_drivers/devices)
        target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/sensing_board_Linux_drivers/drivers)
    endif()
else()
    message(STATUS "Non-cross-compiling detected...")
    add_subdirectory(fake_drivers)
    target_link_libraries(uav_test fake_devices)
    target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/fake_divers/devices)
    target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/fake_divers/drivers)
    # 非交叉编译时链接的库
endif()

target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/mavlink)
target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/mavlink/commonACFly)
target_include_directories(uav_test PRIVATE ${PROJECT_SOURCE_DIR}/mavlink/minimalACFly)

target_compile_options(uav_test PRIVATE -Wno-address-of-packed-member)
